/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.trick.admin.binding;

import javafx.beans.binding.BooleanBinding;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;

/**
 *
 * @author takahara
 */
public class AddChannelButtonBinding extends BooleanBinding {

    private ComboBox siteComboBox;
    private TextField keyTextField;
    private TextField nameTextField;

    public AddChannelButtonBinding(ComboBox siteComboBox, TextField keyTextField, TextField nameTextField) {
        this.siteComboBox = siteComboBox;
        this.keyTextField = keyTextField;
        this.nameTextField = nameTextField;

        super.bind(this.siteComboBox.valueProperty());
        super.bind(this.keyTextField.textProperty());
        super.bind(this.nameTextField.textProperty());
    }

    @Override
    protected boolean computeValue() {

        if (siteComboBox.getValue() == null) return true;

        String key = keyTextField.getText().trim();
        if(key == null) return true;
        if(key.equals("")) return true;

        String name = nameTextField.getText().trim();
        if(name == null) return true;
        if(name.equals("")) return true;

        return false;
    }

}
